<template>
  <!-- 搜索结果呈现的组件 -->
  <div class="search-result">
    <van-list
      v-model="loading"
      :finished="finished"
      :error.sync="error"
      error-text="请求失败，点击重新加载"
      finished-text="没有更多了"
      @load="onLoad"
    >
      <van-cell v-for="(item,index) in list" :key="index" >
         <span>{{item.title}}</span>
      </van-cell>
    </van-list>
  </div>
</template>

<script>
import {getSearchResult} from '@/service/getDate'
export default {
  name: 'searchResult',
  data() {
    return {
      list: [],
      loading: false,
      finished: false,
      error:false,
      page: 1, // 页数
      per_page: 20, // 每页要呈现的数据数量
    };
  },
  props: {
    // 搜索框输入的文本
    resultValue: {
      type: String,
      required: true,
    }
  },
 
  methods: {
   async onLoad() {
    console.log(this.resultValue);
       try {
        const {data} = await getSearchResult({
          page: this.page,
          per_page: this.per_page,
          q: this.resultValue
        })
        const { results }  = data.data
        console.log(results)
        this.list.push(...results)
        this.finished = true
       } catch(err) {
        console.log(err);
       }
    },
  },
}
</script>

<style lang="scss" scoped>

</style>